package com.multicampus.minishop.view.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.multicampus.minishop.framework.Action;
import com.multicampus.minishop.services.user.UserService;
import com.multicampus.minishop.services.user.impl.UserServiceImpl;
import com.multicampus.minishop.user.vo.UserVO;


public class UpdateUserAction extends Action {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		
		String userId=(String)request.getParameter("userId");
		
		UserVO vo=new UserVO();
		vo.setUserId(userId);
		vo.setUserName(request.getParameter("userName"));
		vo.setAddr(request.getParameter("addr"));
		vo.setPhone(request.getParameter("cellPhone"));
		vo.setEmail(request.getParameter("email"));
		
		UserService service=new UserServiceImpl();
		service.updateUser(vo);
		
		
		HttpSession session=request.getSession();
		String sessionId=((UserVO)session.getAttribute("user")).getUserId();
		if(sessionId.equals(userId))
			session.setAttribute("user", vo);
		
		return "redirect:/getUser.do?userId="+userId;
	}

}
